package cn.iocoder.yudao.module.famous.doctor.controller.admin.reply;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.reply.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.reply.FamReplyDO;
import cn.iocoder.yudao.module.famous.doctor.convert.reply.FamReplyConvert;
import cn.iocoder.yudao.module.famous.doctor.service.reply.FamReplyService;

@Tag(name = "管理后台 - 谈论会回复")
@RestController
@RequestMapping("/famous.doctor/fam-reply")
@Validated
public class FamReplyController {

    @Resource
    private FamReplyService famReplyService;

    @PostMapping("/create")
    @Operation(summary = "创建谈论会回复")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-reply:create')")
    public CommonResult<Long> createFamReply(@Valid @RequestBody FamReplyCreateReqVO createReqVO) {
        return success(famReplyService.createFamReply(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新谈论会回复")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-reply:update')")
    public CommonResult<Boolean> updateFamReply(@Valid @RequestBody FamReplyUpdateReqVO updateReqVO) {
        famReplyService.updateFamReply(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除谈论会回复")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-reply:delete')")
    public CommonResult<Boolean> deleteFamReply(@RequestParam("id") Long id) {
        famReplyService.deleteFamReply(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得谈论会回复")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-reply:query')")
    public CommonResult<FamReplyRespVO> getFamReply(@RequestParam("id") Long id) {
        FamReplyDO famReply = famReplyService.getFamReply(id);
        return success(FamReplyConvert.INSTANCE.convert(famReply));
    }

    @GetMapping("/list")
    @Operation(summary = "获得谈论会回复列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-reply:query')")
    public CommonResult<List<FamReplyRespVO>> getFamReplyList(@RequestParam("ids") Collection<Long> ids) {
        List<FamReplyDO> list = famReplyService.getFamReplyList(ids);
        return success(FamReplyConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得谈论会回复分页")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-reply:query')")
    public CommonResult<PageResult<FamReplyRespVO>> getFamReplyPage(@Valid FamReplyPageReqVO pageVO) {
        PageResult<FamReplyDO> pageResult = famReplyService.getFamReplyPage(pageVO);
        return success(FamReplyConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出谈论会回复 Excel")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-reply:export')")
    @OperateLog(type = EXPORT)
    public void exportFamReplyExcel(@Valid FamReplyExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<FamReplyDO> list = famReplyService.getFamReplyList(exportReqVO);
        // 导出 Excel
        List<FamReplyExcelVO> datas = FamReplyConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "谈论会回复.xls", "数据", FamReplyExcelVO.class, datas);
    }

}
